import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';

class CommonData {
  static int MIN_SLEEP_HOURS = 3; //最少够记录的时间hour

  //program的状态
  static const int program_status_not_start = 1;
  static const int program_status_started = 2;
  static const int program_status_finished = 3;

  static String PLAN_DETAIL_EXERCISE = "Exercise";
  static String PLAN_DETAIL_SLEEP = "Sleep";
  static String PLAN_DETAIL_STRESS = "Stress";
  static String PLAN_DETAIL_RISKY = "Risky";
  static String PLAN_DETAIL_NUTRITION = "Nutrition";
  static String PLAN_DETAIL_SOCIAL = "Social";

  //===============

  static const String BLOOD_PRESSURE_HYPOTENSION = "Hypotension";
  static const String BLOOD_PRESSURE_NORMAL = "Normal";
  static const String BLOOD_PRESSURE_ELEVATED = "Elevated";

  static const String BLOOD_PRESSURE_HYPERTENSIVE1 = "Hypertension I";
  static const String BLOOD_PRESSURE_HYPERTENSIVE2 = "Hypertension II";
  static const String BLOOD_PRESSURE_HYPERTENSIVE = "Hypertensive";

  //===============

  static const Map<String, String> MOTIVATION_SLEEP = {"tag": "0", "value": "Sleep"};
  static const Map<String, String> MOTIVATION_STRESS = {"tag": "1", "value": "Stress"};
  static const Map<String, String> MOTIVATION_NUTRITION = {"tag": "2", "value": "Nutrition"};
  static const Map<String, String> MOTIVATION_EXERCISE = {"tag": "3", "value": "Exercise"};
  static const Map<String, String> MOTIVATION_CONNECTION = {"tag": "4", "value": "Connection"};
  static const Map<String, String> MOTIVATION_MENTAL_HEALTH = {"tag": "5", "value": "Mental Health"};

  static Map<String, dynamic> MotivationTagMap = {
    "0": MOTIVATION_SLEEP,
    "1": MOTIVATION_STRESS,
    "2": MOTIVATION_NUTRITION,
    "3": MOTIVATION_EXERCISE,
    "4": MOTIVATION_CONNECTION,
    "5": MOTIVATION_MENTAL_HEALTH,
  };

  static List<String> allTagsSet = [
    "Heart attack & stroke prevention",
    "Congestive heart failure",
    "Metabolic syndrome",
    "Peripheral vascular disease",
    "Pre-diabetes",
    "Obesity/weight loss",
  ];

  static String getProgramStatusText(int status) {
    String text = "";
    switch (status) {
      case program_status_not_start:
        text = "Not start";
        break;
      case program_status_started:
        text = "Started";
        break;
      case program_status_finished:
        text = "Finished";
        break;
    }
    return text;
  }

  static getBoxShadow() {
    return [
      //box-shadow: 0px 3px 8px 0px rgba(148, 131, 194, 0.17);
      const BoxShadow(color: Color(0x2c9483c2), offset: Offset(0, 3), blurRadius: 8, spreadRadius: 0)
    ];
  }

  static getAllMotivations() {
    return List.of([MOTIVATION_SLEEP, MOTIVATION_STRESS, MOTIVATION_NUTRITION, MOTIVATION_EXERCISE, MOTIVATION_CONNECTION, MOTIVATION_MENTAL_HEALTH]);
  }

  static List<Map<String, String>> motivationsList2Obj(String motivations) {
    var motions = getAllMotivations();
    List<Map<String, String>> tagSelected = [];
    if (motivations.isNotEmpty == true) {
      var motionsItem = motivations.split(",");
      for (String text in motionsItem) {
        for (Map<String, String> m in motions) {
          if (text == m['tag']) {
            tagSelected.add(m);
          }
        }
      }
    }
    return tagSelected;
  }


  static Map<String, dynamic> measureMaps = {
    "Grain": [
      "images/bg_measure_grain1.png",
      "images/bg_measure_grain2.png",
      "images/bg_measure_grain3.png",
    ],
    "Meats": [
      "images/bg_measure_meat_11.png",
      "images/bg_measure_meat_12.png",
      "images/bg_measure_meat_13.png",
      "images/bg_measure_meat_14.png",
      "images/bg_measure_meat_15.png",
    ],
    "Nuts": [
      "images/icon_meal_nuts_measure1.png",
      "images/icon_meal_nuts_measure2.png",
      "images/icon_meal_nuts_measure3.png",
      "images/icon_meal_nuts_measure4.png",
      "images/icon_meal_nuts_measure5.png",
    ],
    "Vegetables": [
      "images/icon_measure_vegetable1.png",
      "images/icon_measure_vegetable2.png",
      "images/icon_measure_vegetable3.png",
    ],
    "Fruit": [
      "images/icon_measure_fruits1.png",
      "images/icon_measure_fruits2.png",
      "images/icon_measure_fruits3.png",
      "images/icon_measure_fruits4.png",
      "images/icon_measure_fruits5.png",
      "images/icon_measure_fruits6.png",
    ],
    "Dairy": [
      "images/icon_measure_luqicd1.png",
      "images/icon_measure_luqicd2.png",
      "images/icon_measure_luqicd3.png",
      "images/icon_measure_luqicd4.png",
    ],
    "Fat": [
      "images/icon_measure_oil1.png",
      "images/icon_measure_oil2.png",
    ],
    "Sugar": ["images/icon_meaure_sugary1.png", "images/icon_meaure_sugary2.png", "images/icon_meaure_sugary3.png", "images/icon_meaure_sugary4.png"]
  };

  static List<String> getMeasureImgs(String key) {
    return measureMaps[key] as List<String>;
  }

  //获取血压等级
  static List<String> getBloodPressureLevel(int sys, int dia) {
    String level = "";
    String range = "";
    if (sys >= 180 || dia > 110) {
      level = BLOOD_PRESSURE_HYPERTENSIVE; //超高压
      range = "SYS >=180 or DIA>110";
    } else if ((sys >= 160 && sys < 180) || (dia >= 100 && dia < 110)) {
      level = BLOOD_PRESSURE_HYPERTENSIVE2; //二级高血压
      range = "SYS:160-179 or DIA:100-110";
    } else if ((sys >= 140 && sys < 160) || (dia >= 90 && dia < 100)) {
      level = BLOOD_PRESSURE_HYPERTENSIVE1; //一级高血压
      range = "SYS:140-159 or DIA:90-99";
    } else if ((sys >= 130 && sys < 140) || (dia >= 80 && dia < 90)) {
      level = BLOOD_PRESSURE_ELEVATED; //偏高
      range = "SYS:130-139 or DIA:80-89";
    } else if ((sys < 90 || dia < 60)) {
      level = BLOOD_PRESSURE_HYPOTENSION; //低血压
      range = " SYS < 90 or DIA  <60";
    } else if ((sys >= 90 && sys < 130) || (dia >= 60 && dia < 80)) {
      level = BLOOD_PRESSURE_NORMAL; //正常
      range = " SYS:90-129 or DIA:60-79";
    } else {
      level = "Unknown"; //正常
      range = "Unknown";
    }

    return [level, range];
    // return ["",""];
  }

  static List<Color> getColorByLevel(String level) {
    Color bgColor = const Color(0x260F66EB);
    Color textColor = const Color(0xff154DA2);

    switch (level) {
      case CommonData.BLOOD_PRESSURE_HYPOTENSION:
        bgColor = const Color(0x260F66EB);
        textColor = const Color(0xff154DA2);
        break;

      case CommonData.BLOOD_PRESSURE_NORMAL:
        bgColor = const Color(0x1A41AE6B);
        textColor = const Color(0xff227140);
        break;

      case CommonData.BLOOD_PRESSURE_ELEVATED:
        bgColor = const Color(0x26FDD700);
        textColor = const Color(0xffF6B83D);
        break;

      case CommonData.BLOOD_PRESSURE_HYPERTENSIVE1:
        bgColor = const Color(0x26FDD700);
        textColor = const Color(0xffF6B83D);
        break;

      case CommonData.BLOOD_PRESSURE_HYPERTENSIVE2:
        bgColor = const Color(0x1ABD3B0E);
        textColor = const Color(0xffBD3B0E);
        break;

      case CommonData.BLOOD_PRESSURE_HYPERTENSIVE:
        bgColor = const Color(0x1ABD3B0E);
        textColor = Colors.red;
        break;
    }

    return [bgColor, textColor];
  }

  static String getBloodLevelIcon(String level) {
    String icon = "";
    if (level == BLOOD_PRESSURE_HYPERTENSIVE2|| level == BLOOD_PRESSURE_HYPERTENSIVE ) {
      icon = "images/icon_blood_level_seek_help.png";
    } else if (level == BLOOD_PRESSURE_HYPOTENSION || level == BLOOD_PRESSURE_ELEVATED || level == BLOOD_PRESSURE_HYPERTENSIVE1 ) {
      icon = "images/icon_blood_level_medium.png";
    } else {
      icon = "images/icon_blood_level_good.png";
    }
    return icon;
  }



  ///身高选择
  static List<String> createHeightChange() {
    List<String> valueRange = List.of([]);
    for (int i = 100; i <= 300; i++) {
      valueRange.add(i.toString());
    }
    return valueRange;
  }

  ///身高单位选择
  static List<String> createHeightUnitChange() {
    List<String> valueRange = List.of([]);
    valueRange.add("CM");
    // valueRange.add("Inches");
    return valueRange;
  }


  ///生成重量选择数据，整数
 static List<String> createIntWeightValueChange() {
    List<String> valueRange = List.of([]);
    for (var i = 20; i <= 300; i++) {
      valueRange.add("${i}");
    }
    return valueRange;
  }

  ///生成重量选择数据，小数
  static List<String> createFloatWeightValueChange() {
    List<String> valueRange = List.of([]);
    valueRange.add("0");
    for (var i = 1; i < 10; i++) {
      valueRange.add((i * 0.1).toStringAsFixed(1));
    }
    return valueRange;
  }

  ///生成重量选择数据，单位
  static List<String> createUnitWeightValueChange() {
    List<String> valueRange = List.of([]);
    valueRange.add("KG");
    // valueRange.add("LBs");
    return valueRange;
  }

  ///腰围范围
  static List<String> createWaistChange() {
    List<String> valueRange = List.of([]);
    for (int i = 30; i <= 200; i++) {
      valueRange.add(i.toString());
    }
    return valueRange;
  }

  ///臀围
  static List<String>  createHipChange() {
    List<String> valueRange = List.of([]);
    for (int i = 40; i <= 200; i++) {
      valueRange.add(i.toString());
    }
    return valueRange;
  }

  ///脖围
  static List<String> createNecKChange() {
    List<String> valueRange = List.of([]);
    for (int i = 10; i <= 80; i++) {
      valueRange.add(i.toString());
    }
    return valueRange;
  }



  ///获取血压等级描述
  static List<Widget> createLevelWidgets() {
    List<Widget> all = [];

    all.add(createBloodPressureLevelWidgets("Hypotension", "SYS < 90 or DIA  <60", const Color(0xffCCD9FA)));
    all.add(createBloodPressureLevelWidgets("Normal", "SYS 90-129 or DIA 60-79", const Color(0xffD7EACA)));
    all.add(createBloodPressureLevelWidgets("Elevated", "SYS 130-139 or DIA 80-89", const Color(0xffF7CDC4)));
    all.add(createBloodPressureLevelWidgets("Hypertension I", "SYS 140-159 or DIA 90-99", const Color(0xffF7CDC4)));
    all.add(createBloodPressureLevelWidgets("Hypertension II", "SYS 160-179 or DIA 100-110", const Color(0xffFFA49E)));
    all.add(createBloodPressureLevelWidgets("Hypertensive", "SYS ≥ 180 or DIA > 110", const Color(0xffE57373)));

    return all;
  }


  ///获取血压level描述，等
  static Widget createBloodPressureLevelWidgets(String title, String subTitle, Color color) {
    return Container(
      margin: EdgeInsets.only(top: 10.h, bottom: 10.h),
      child: Row(
        children: [
          ClipOval(
            child: Container(
              width: 10.w,
              height: 10.w,
              color: color,
            ),
          ),
          SizedBox(
            width: 10.w,
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "${title}",
                style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 14.sp, color: const Color(0xff333333)),
              ),
              Text(
                "${subTitle}",
                style: GoogleFonts.poppins(fontSize: 12.sp, fontWeight: FontWeight.w400, color: const Color(0xff888888)),
              )
            ],
          )
        ],
      ),
    );
  }


}
